package com.atguigu.spzx.user.controller;

import com.atguigu.spzx.model.dto.api.ApiUserLoginDTO;
import com.atguigu.spzx.model.dto.api.ApiUserRegisterDTO;
import com.atguigu.spzx.model.entity.user.UserInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.user.UserInfoVo;
import com.atguigu.spzx.user.service.UserInfoService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author LT
 * @create 2024-03-27-13:58
 */
@RestController
@RequestMapping("/api/user/userInfo")
public class UserInfoController {

    @Resource
    UserInfoService userInfoService;

    @PostMapping("/register")
    public Result register(@RequestBody ApiUserRegisterDTO userRegisterDTO){
        userInfoService.register(userRegisterDTO);
        return Result.ok();
    }

    @PostMapping("/login")
    public Result login(@RequestBody ApiUserLoginDTO userLoginDTO){
        String token = userInfoService.login(userLoginDTO);
        return Result.ok(token);
    }

    @GetMapping("/auth/getCurrentUserInfo")
    public Result getCurrentUserInfo(@RequestHeader("token") String token){
       UserInfoVo userInfo = userInfoService.getCurrentUserInfo(token);
        return Result.ok(userInfo);
    }
    @GetMapping("/logout")
    public Result logout(@RequestHeader("token") String token){
        userInfoService.logout(token);
        return Result.ok();
    }



}
